在WSL启用ssh 您所在的位置:网站首页 wsl 开机自动启动 在WSL启用ssh

在WSL启用ssh

#在WSL启用ssh| 来源: 网络整理| 查看: 265

最好的Linux发行版是Windows10!

以下内容仅适用于Debian/Ubuntu.

安装并启动sshd

首先, 需要在发行版中确认存在openssh-server这个包.和正常发行版不同的是, wsl中并没有使用systemd来启动系统.War, war never changes因此, 想要启动ssh-server必须通过/etc/init.d/ssh来实现.

注意此处要修改/etc/ssh/sshd_config. 其中的Port建议修改为大于1024的端口, PasswordAuthentication建议修改为yes.

测试/etc/init.d/ssh start, 成功后进行下一步.

开机自启动sshd

wsl在执行第一个命令之前不会启动, 因此, 我们需要编写一个start_sshd.vbs脚本, 添加到计划任务里的开机启动事件.

脚本内容为:

123Set wshell=wscript.createobject("wscript.shell")wshell.run "C:\Windows\System32\wsl.exe sudo /etc/init.d/ssh start",0Set wshell=Nothing

然而sudo命令需要输入密码才能启动, 为了bypass这一点, 需要修改sudo文件.

1sudo visudo

添加

12# for wsl start sshd%sudo ALL=NOPASSWD: /etc/init.d/ssh start

并保存.

完成后请务必重启系统测试.



【本文地址】

公司简介

联系我们

今日新闻

    推荐新闻

    专题文章
      CopyRight 2018-2019 实验室设备网 版权所有